<?php //callback for ajax/json

/**
 * mapPointPlot is ajax/json callback page
 * 
 * this was written for ajax calls related to the map
 * functionality in bookstore.  this was a shortcut, a
 * bad shortcut and poses some security risks.
 * 
 * @todo this file was relocated below the docroot; file that
 * copy and refactor that code into the component properly.
 * 
 * @deprecated this particular code was relocated and
 * modified, however EITHER should exist in their current
 * manifests. the code needs to be merged into the component
 *
 */
class mapPointPlot {

function __construct(){
	/*
	//$this->site_to_query = 'http://www.booksite.com/texis/scripts/oop/rawsearch_ing/rawdetail.html?sid=3401';
	//$this->url = $this->site_to_query.'&amp;isbn='.$_GET['isbn'];
	//var_dump(construct);
	*/
//	$base = $_SERVER['DOCUMENT_ROOT'];
//	$old_path = get_include_path();
//	if(file_exists($base ."/scripts/db/jm.php")){
//	require($base.'/scripts/db/jm.txt');
//	var_dump($old_path);
	}
	/*
	//ini_set('include_path',$old_path.':/var/scripts/db');
	$new_path = get_include_path();
	//var_dump($new_path);
	*/
	//require("db/test.php");
	
//	var_dump();
	/*
	var_dump('done require');
	*/
	
	$db_host = '127.0.0.1';
	$db_user = 'jm';
	$db_pass = 'bpkrak603';
	$db_db = 'jm';
	/**/
	$this->db_prefix = 'jos_';
	$this->db_con = mysql_connect($db_host,$db_user,$db_pass) or die('cannot connect to database server');
	mysql_select_db($db_db,$this->db_con) or die('no such database');
	
}//end constructor

function getPath($mapId = ''){
	
	
	(empty($mapId))? $where = '': $where = "WHERE id='".$mapId."'";
	$query = 'SELECT path FROM '.$this->db_prefix.'maps '.$where;
	$results = mysql_query($query) or die('problem with query');
	$row = mysql_fetch_object($results);
	return $row->path;
	
}//end getPath method


}//end class
//if(empty($long))$long = -63.10774861954596;
//if(empty($lat)) $lat = 46.2899306519141;

// First we load the background/base map. We assume it's located in same dir as the script.
// This can be any format but we are using JPG in this example
// We will also allocate the color for the marker

//get image
//var_dump('begin');
(empty($_GET['image'])) ? $pt['image'] = '' : $pt['image'] = $_GET['image'];
$map_obj = new mapPointPlot();
$img_path = $map_obj->getPath($pt['image']);
//var_dump($img_path);
$im = imagecreatefromjpeg("/var/www".$img_path);

$green = '';
$color = imagecolorallocate ($im, 35,142,35);

$pt['x'] = $_GET['x'];
$pt['y'] = $_GET['y'];
//$x = $_GET['x'];
//$y = $_GET['y'];
// Next need to find the base image size.
// We need these variables to be able scale the long/lat coordinates.

//$scale_x = imagesx($im);
//$scale_y = imagesy($im);

// Now we convert the long/lat coordinates into screen coordinates

//$pt = getlocationcoords($x, $y, $scale_x, $scale_y);

// Now mark the point on the map using a red 4 pixel rectangle

//imagefilledrectangle($im,$pt["x"]-2,$pt["y"]-2,$pt["x"]+2,$pt["y"]+2,$color);
imagefilledellipse($im,$pt["x"],$pt["y"],6,6,$color);
// Return the map image. We are using a PNG format as it gives better final image quality than a JPG

header ("Content-type: image/png");
	//$plotted = imagepng($im);
imagepng($im);
	//imagedestroy($im); 
	//return $plotted;

/*
if($_GET['isbn']){
	$query = new detail_query();
	$query->_runCurl($query->url);
	//var_dump($query);
	$obj = $query->_parseDetails($query->_results);
	$generic_img = 'images/no_book_image.gif';
	if(empty($obj->graphics) || strstr($obj->graphics, 'http:') == FALSE){
		$obj->graphics = $generic_img;
	}
	//$ann = preg_quote($obj->annotation);
	$ann = preg_replace('/"/','\"',html_entity_decode($obj->annotation));
	$ann = preg_replace("/'/","\'",$ann);
	echo '{"annotation":"'.$ann.'","graphics":"'.$obj->graphics.'"}';
}
*/

?>